package com.example.test;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.matcher.ElementMatchers;

/**
 * https://bytebuddy.net/#/
 * 
 * @author simple
 *
 */
public class THello {

	public static void main(String[] args) throws InstantiationException, IllegalAccessException {

		Class<?> dynamicType = new ByteBuddy()
				  .subclass(Object.class)
				  .method(ElementMatchers.named("toString"))
				  .intercept(FixedValue.value("Hello World!"))
				  .make()
//				  .load(THello.class.getClassLoader())
				  .load(ClassLoader.getSystemClassLoader())
				  .getLoaded();
		
		System.err.println(dynamicType.newInstance().toString());
	}
}